Repetier-Firmware  1.0.0
Endstops.h
Go to the documentation of this file.
1 /*
2  This file is part of Repetier-Firmware.
3 
4  Repetier-Firmware is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Repetier-Firmware is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 
19 #ifndef _ENDSTOPS_H
20 #define _ENDSTOPS_H
21 
22 #define ENDSTOP_X_MIN_ID 1
23 #define ENDSTOP_X_MAX_ID 2
24 #define ENDSTOP_Y_MIN_ID 4
25 #define ENDSTOP_Y_MAX_ID 8
26 #define ENDSTOP_Z_MIN_ID 16
27 #define ENDSTOP_Z_MAX_ID 32
28 #define ENDSTOP_Z2_MIN_ID 64
29 #define ENDSTOP_Z2_MINMAX_ID 64
30 #define ENDSTOP_Z_PROBE_ID 128
31 
32 // These endstops are only used with EXTENDED_ENDSTOPS
33 #define ENDSTOP_X2_MIN_ID 1
34 #define ENDSTOP_X2_MAX_ID 2
35 #define ENDSTOP_Y2_MIN_ID 4
36 #define ENDSTOP_Y2_MAX_ID 8
37 #define ENDSTOP_Z2_MAX_ID 16
38 #define ENDSTOP_Z3_MIN_ID 32
39 #define ENDSTOP_Z3_MAX_ID 64
40 
41 #if IS_MAC_TRUE(MIN_HARDWARE_ENDSTOP_X2) || IS_MAC_TRUE(MAX_HARDWARE_ENDSTOP_X2) || IS_MAC_TRUE(MIN_HARDWARE_ENDSTOP_Y2) || IS_MAC_TRUE(MAX_HARDWARE_ENDSTOP_Y2) || IS_MAC_TRUE(MAX_HARDWARE_ENDSTOP_Z2) || IS_MAC_TRUE(MAX_HARDWARE_ENDSTOP_Z3) || IS_MAC_TRUE(MIN_HARDWARE_ENDSTOP_Z3)
42 #define EXTENDED_ENDSTOPS 1
43 #endif
44 
45 class Endstops {
47  static flag8_t lastRead;
49  #ifdef EXTENDED_ENDSTOPS
50  static flag8_t lastState2;
51  static flag8_t lastRead2;
52  static flag8_t accumulator2;
53  #endif
54  public:
55  static void update();
56  static void report();
57  static INLINE bool anyXYZMax() {
58  return (lastState & (ENDSTOP_X_MAX_ID | ENDSTOP_Y_MAX_ID | ENDSTOP_Z_MAX_ID)) != 0;
59  }
60  static INLINE bool anyXYZ() {
61  #ifdef EXTENDED_ENDSTOPS
63  lastState2 != 0;
64  #else
66  #endif
67  }
68  static INLINE bool anyEndstopHit() {
69  #ifdef EXTENDED_ENDSTOPS
70  return lastState != 0 || lastState2 != 0;
71  #else
72  return lastState != 0;
73  #endif
74  }
75  static INLINE void resetAccumulator() {
76  accumulator = 0;
77  #ifdef EXTENDED_ENDSTOPS
78  accumulator2 = 0;
79  #endif
80  }
81  static INLINE void fillFromAccumulator() {
82  lastState = accumulator;
83  #ifdef EXTENDED_ENDSTOPS
84  lastState2 = accumulator2;
85  #endif
86  }
87  static INLINE bool xMin() {
88  #if (X_MIN_PIN > -1) && MIN_HARDWARE_ENDSTOP_X
89  return (lastState & ENDSTOP_X_MIN_ID) != 0;
90  #else
91  return false;
92  #endif
93  }
94  static INLINE bool xMax() {
95  #if (X_MAX_PIN > -1) && MAX_HARDWARE_ENDSTOP_X
96  return (lastState & ENDSTOP_X_MAX_ID) != 0;
97  #else
98  return false;
99  #endif
100  }
101  static INLINE bool yMin() {
102  #if (Y_MIN_PIN > -1) && MIN_HARDWARE_ENDSTOP_Y
103  return (lastState & ENDSTOP_Y_MIN_ID) != 0;
104  #else
105  return false;
106  #endif
107  }
108  static INLINE bool yMax() {
109  #if (Y_MAX_PIN > -1) && MAX_HARDWARE_ENDSTOP_Y
110  return (lastState & ENDSTOP_Y_MAX_ID) != 0;
111  #else
112  return false;
113  #endif
114  }
115  static INLINE bool zMin() {
116  #if (Z_MIN_PIN > -1) && MIN_HARDWARE_ENDSTOP_Z
117  return (lastState & ENDSTOP_Z_MIN_ID) != 0;
118  #else
119  return false;
120  #endif
121  }
122  static INLINE bool zMax() {
123  #if (Z_MAX_PIN > -1) && MAX_HARDWARE_ENDSTOP_Z
124  return (lastState & ENDSTOP_Z_MAX_ID) != 0;
125  #else
126  return false;
127  #endif
128  }
129  static INLINE bool z2MinMax() {
130  #if (Z2_MINMAX_PIN > -1) && MINMAX_HARDWARE_ENDSTOP_Z2
131  return (lastState & ENDSTOP_Z2_MIN_ID) != 0;
132  #else
133  return false;
134  #endif
135  }
136  static INLINE bool zProbe() {
137  #if FEATURE_Z_PROBE
138  return (lastState & ENDSTOP_Z_PROBE_ID) != 0;
139  #else
140  return false;
141  #endif
142  #ifdef EXTENDED_ENDSTOPS
143  static INLINE bool x2Min() {
144  #if HAS_PIN(X2_MIN_PIN) && MIN_HARDWARE_ENDSTOP_X2
145  return (lastState2 & ENDSTOP_X2_MIN_ID) != 0;
146  #else
147  return false;
148  #endif
149  }
150  static INLINE bool x2Max() {
151  #if HAS_PIN(X2_MAX_PIN) && MAX_HARDWARE_ENDSTOP_X2
152  return (lastState2 & ENDSTOP_X2_MAX_ID) != 0;
153  #else
154  return false;
155  #endif
156  }
157  static INLINE bool y2Min() {
158  #if HAS_PIN(Y2_MIN_PIN) && MIN_HARDWARE_ENDSTOP_Y2
159  return (lastState2 & ENDSTOP_Y2_MIN_ID) != 0;
160  #else
161  return false;
162  #endif
163  }
164  static INLINE bool y2Max() {
165  #if HAS_PIN(Y2_MAX_PIN) && MAX_HARDWARE_ENDSTOP_Y2
166  return (lastState2 & ENDSTOP_Y2_MAX_ID) != 0;
167  #else
168  return false;
169  #endif
170  }
171  static INLINE bool z2Max() {
172  #if HAS_PIN(Z2_MAX_PIN) && MAX_HARDWARE_ENDSTOP_Z2
173  return (lastState2 & ENDSTOP_Z2_MAX_ID) != 0;
174  #else
175  return false;
176  #endif
177  }
178  static INLINE bool z3Max() {
179  #if HAS_PIN(Z3_MAX_PIN) && MAX_HARDWARE_ENDSTOP_Z3
180  return (lastState2 & ENDSTOP_Z3_MAX_ID) != 0;
181  #else
182  return false;
183  #endif
184  }
185  static INLINE bool z3Min() {
186  #if HAS_PIN(Z3_MIN_PIN) && MIN_HARDWARE_ENDSTOP_Z3
187  return (lastState2 & ENDSTOP_Z3_MIN_ID) != 0;
188  #else
189  return false;
190  #endif
191  }
192  #endif
193  }
194 };
195 
196 #endif
static INLINE bool anyXYZ()
Definition: Endstops.h:60
static INLINE bool yMin()
Definition: Endstops.h:101
#define ENDSTOP_X_MIN_ID
Definition: Endstops.h:22
static INLINE bool zMax()
Definition: Endstops.h:122
static flag8_t accumulator
Definition: Endstops.h:48
uint8_t flag8_t
Definition: HAL.h:159
#define ENDSTOP_Z2_MAX_ID
Definition: Endstops.h:37
static INLINE bool z2MinMax()
Definition: Endstops.h:129
#define ENDSTOP_Y2_MAX_ID
Definition: Endstops.h:36
Definition: Endstops.h:45
#define ENDSTOP_Z_PROBE_ID
Definition: Endstops.h:30
static INLINE bool yMax()
Definition: Endstops.h:108
static INLINE bool xMin()
Definition: Endstops.h:87
#define ENDSTOP_Y2_MIN_ID
Definition: Endstops.h:35
static INLINE void fillFromAccumulator()
Definition: Endstops.h:81
#define ENDSTOP_X2_MAX_ID
Definition: Endstops.h:34
static INLINE bool xMax()
Definition: Endstops.h:94
#define ENDSTOP_Y_MAX_ID
Definition: Endstops.h:25
#define ENDSTOP_Y_MIN_ID
Definition: Endstops.h:24
static INLINE bool zProbe()
Definition: Endstops.h:136
#define ENDSTOP_X2_MIN_ID
Definition: Endstops.h:33
#define ENDSTOP_Z_MIN_ID
Definition: Endstops.h:26
static INLINE bool zMin()
Definition: Endstops.h:115
static void report()
Definition: Endstops.cpp:141
#define INLINE
Definition: HAL.h:37
#define ENDSTOP_Z3_MAX_ID
Definition: Endstops.h:39
static INLINE bool anyXYZMax()
Definition: Endstops.h:57
#define ENDSTOP_Z2_MIN_ID
Definition: Endstops.h:28
#define ENDSTOP_X_MAX_ID
Definition: Endstops.h:23
static flag8_t lastState
Definition: Endstops.h:46
static void update()
Definition: Endstops.cpp:35
static INLINE void resetAccumulator()
Definition: Endstops.h:75
#define ENDSTOP_Z3_MIN_ID
Definition: Endstops.h:38
#define ENDSTOP_Z_MAX_ID
Definition: Endstops.h:27
static flag8_t lastRead
Definition: Endstops.h:47
static INLINE bool anyEndstopHit()
Definition: Endstops.h:68